package com.tsu.mall.order.Controller;

import com.tsu.mall.common.VO.CheckOutWaresVO;
import com.tsu.mall.common.util.RequestUtil;
import com.tsu.mall.order.entity.MemberAddress;
import com.tsu.mall.order.service.CheckOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/checkout")
public class CheckOutController {
    @Autowired
    private CheckOutService checkOutService;
    @GetMapping("/checkoutPage")
    public String checkoutPage(String ids, Model model){
        //查出确认订单页面需要的该会员的所有商品信息
        List<CheckOutWaresVO> list=checkOutService.selectByIds(ids);
        model.addAttribute("CheckOutWaresInfo",list);
        model.addAttribute("ids",ids);
        //查询当前会员地址表中的所有地址
        List<MemberAddress> address=checkOutService.selectByMemberId(RequestUtil.getCurrent().getId());
        model.addAttribute("address",address);
        return "checkout";
    }
    @PostMapping("/checkoutWaresInfo")
    @ResponseBody
    public List<CheckOutWaresVO> checkoutWaresInfo(String ids){
        return checkOutService.selectByIds(ids);
    }
}
